package com.utils;

import android.content.Context;
import android.graphics.Typeface;

import java.lang.reflect.Field;

/**
 * created by zhengweis on 2018/12/11.
 * description：
 */
public class TypeFaceUtils {
    public static String PINGFANG_FINE = "fonts/pingfang_fine.ttf"; //苹方细

    /**
     * 初始化全局字体
     *
     * @param context
     * @param type
     */
    public static void initTypeFace(Context context, String type) {
        Typeface mTypeface = Typeface.createFromAsset(context.getAssets(), type);
        try {
            Field field = Typeface.class.getDeclaredField("MONOSPACE");
            field.setAccessible(true);
            field.set(null, mTypeface);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
